﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace WindowsPhone.TestFramework.Tools
{
    public static class ExtendedAssert
    {
        public static Exception Throws<TExceptionType>(Action target)
            where TExceptionType : Exception
        {
            try
            {
                target();
                Assert.Fail("No Exception was thrown.");
            }
            catch (TExceptionType ex)
            {
                return ex;
            }
            catch (Exception e)
            {
                Assert.Fail(string.Format("Expected exception of type {0}, but was exception thrown was of type {1}", typeof(TExceptionType).AssemblyQualifiedName, e.GetType().AssemblyQualifiedName));
            }

            return null;
        }

        public static void IsNotEmpty(string value)
        {
            Assert.AreNotEqual(String.Empty, value, "String cannot be empty.");
        }

        public static void IsNotNullOrEmpty(string value)
        {
            Assert.IsNotNull(value);
            IsNotEmpty(value);
        }
    }
}
